//
//  CZFoodTyoeViewController.m
//  UISplitViewController练习
//
//  Created by chao on 15/2/28.
//  Copyright (c) 2015年 chao. All rights reserved.
//

#import "CZFoodTyoeViewController.h"
#import "CZFoodType.h"
#import "MJExtension.h"

@interface CZFoodTyoeViewController ()
@property (nonatomic, strong) NSArray *foodTypes;
@end

@implementation CZFoodTyoeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"菜系";
    
    self.tableView.tableFooterView = [[UIView alloc] init];
    NSIndexPath *path = [NSIndexPath indexPathForRow:0 inSection:0];
    [self.tableView selectRowAtIndexPath:path animated:YES scrollPosition:UITableViewScrollPositionMiddle];
    [self tableView:nil didSelectRowAtIndexPath:path];
}
- (NSArray *)foodTypes {
    if (_foodTypes == nil) {
        _foodTypes = [CZFoodType objectArrayWithFilename:@"food_types.plist"];
    }
    return _foodTypes;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.foodTypes.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"foodType";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    CZFoodType *foodType = self.foodTypes[indexPath.row];
    cell.textLabel.text = foodType.name;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if ([self.delegate respondsToSelector:@selector(foodTyoeViewController:didSelectedFoodType:)]) {
        CZFoodType *type = _foodTypes[indexPath.row];
        [self.delegate foodTyoeViewController:self didSelectedFoodType:type];
    }
}
@end
